package com.hfjyz.examination.util;

import java.security.MessageDigest;

import org.apache.commons.codec.binary.Base64;

public class CryptUtil {

	public static String encrypt(String normal) throws Exception {
		MessageDigest md5 = MessageDigest.getInstance("md5");
		byte[] digest = md5.digest(normal.getBytes("UTF-8"));
		return Base64.encodeBase64String(digest);
	}

	public static String encode(String normal) throws Exception {
		return Base64.encodeBase64String(normal.getBytes("UTF-8"));
	}

	public static String decode(String encoded) throws Exception {
		return new String(Base64.decodeBase64(encoded), "UTF-8");
	}

	public static void main(String[] args) throws Exception {
		System.out.println(encrypt("123"));
		System.out.println(encrypt("hfjyz"));
		System.out.println(encrypt("overseas"));
		System.out.println(decode(encode("123")));
		System.out.println(decode(encode("hfjyz")));
		System.out.println(decode(encode("中文字符和日本語文字")));
		System.out.println(encrypt("123").length());
		System.out.println(encrypt("123"));
	}

}
